package tr.edu.metu.is.mega.client.service;

import tr.edu.metu.is.mega.common.dto.UserDTO;

import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * GWT user service
 */
@RemoteServiceRelativePath("../GwtUserService")
public interface GwtUserService extends RemoteService {

    /**
     * Utility class for simplifying access to the instance of async service.
     */
    public static class Util {

        private static GwtUserServiceAsync instance;

        public static GwtUserServiceAsync getInstance() {
            if (instance == null) {
                instance = GWT.create(GwtUserService.class);
            }
            return instance;
        }
    }

    /**
     * Login a user.
     * 
     * @param userid user identifier
     * @param password password
     * @return logged in user
     */
    UserDTO login(String userid, String password);

    /**
     * Queries user matching given criteria.
     * 
     * @param config paging parameters
     * @param filter filter instance
     * @return list of users
     */
    PagingLoadResult<UserDTO> getUsers(PagingLoadConfig config, UserDTO filter);

    /**
     * Updates a user record.
     * 
     * @param user user instance
     * @return updated user instance
     */
    UserDTO updateUser(UserDTO user);

    /**
     * Deletes a user record
     * 
     * @param user user to be deleted
     */
    void deleteUser(UserDTO user);

    /**
     * Creates a user record.
     * 
     * @param user user instance
     * @return created user instance
     */
    UserDTO createUser(UserDTO user);

}
